package com.shntec.xtask.test.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

//向数据库添加测试数据
public class InsertTestData {
	public static void main(String[] args) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(
					"jdbc:mysql://127.0.0.1/xtask?useUnicode=true&characterEncoding=UTF-8",
					"xtaskdba","xtaskdba");
			conn.setAutoCommit(false);
			
			//添加日期表数据
			String time = "2012-10-07 10:00:00";
			Long date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_date(dateValue) " +
					"values(" + date + ")");
			ps.execute();
			
			time = "2012-10-08 10:00:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_date(dateValue) " +
					"values(" + date + ")");
			ps.execute();
			
			time = "2012-10-09 10:00:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_date(dateValue) " +
					"values(" + date + ")");
			ps.execute();
			
//			conn.commit();
			
			//添加员工表数据
			ps = conn.prepareStatement("insert into xtask_accounts(username,password,grade,name) " +
					"values('superman','superman',2,'管理员')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_accounts(username,password,grade,name) " +
					"values('panshihao','panshihao',1,'潘世豪')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_accounts(username,password,grade,name) " +
					"values('xurong','xurong',1,'徐荣')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_accounts(username,password,grade,name) " +
					"values('zoulongping','zoulongping',1,'邹龙平')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_accounts(username,password,grade,name) " +
					"values('penglang','penglang',1,'彭琅')");
			ps.execute();
			
//			conn.commit();
			
			//添加项目表数据
			time = "2012-05-09 10:00:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_projects(aid,pname,pdesc,createtime) " +
					"values(2,'打飞机系统','开发出精确的打飞机系统'," + date + ")");
			ps.execute();
			
			time = "2012-06-09 10:00:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_projects(aid,pname,pdesc,createtime) " +
					"values(3,'QQ搜索系统','开发出强大的QQ所搜引擎系统'," + date + ")");
			ps.execute();
			
			time = "2012-08-09 10:00:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_projects(aid,pname,pdesc,createtime) " +
					"values(4,'新华掌媒','强大的android移动软件'," + date + ")");
			ps.execute();
			
//			conn.commit();
			
			//添加例会记录表表数据
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(1,2,3,'调整top3新闻','调整top3新闻完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(1,3,3,'实现新闻分类','实现新闻分类完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(1,4,3,'实现修改字体','修改字体功能完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(1,5,3,'实现删除新闻功能','实现删除新闻功能完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(2,2,3,'调整功能按钮','调整功能按钮完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(2,3,3,'调整新闻封面图片','调整新闻封面图片完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(2,4,3,'实现关于功能','实现关于功能完成')");
			ps.execute();
			
			ps = conn.prepareStatement("insert into xtask_meetings(did,aid,pid,todayPlan,todayComplete) " +
					"values(2,5,3,'实现删除事件功能','实现删除事件功能完成')");
			ps.execute();
			
//			conn.commit();
			
			//添加任务表数据
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			String finish = "2012-10-08 18:00:00";
			Long finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(2,3,null,'调整主界面','对主界面的TOP新闻以及功能按钮进行美化调整',5," + date + ",12,null,null," + finishDate + ",12)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(3,3,null,'完成新闻界面','将新闻界面的分类以及事件封面等完成',5," + date + ",12,null,null," + finishDate + ",12)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(4,3,null,'完成设置界面功能','完成关于,修改字体等功能',5," + date + ",12,null,null," + finishDate + ",12)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(5,3,null,'实现对新闻的删除功能','实现删除新闻,事件以及数据库数据和文件',5," + date + ",12,null,null," + finishDate + ",12)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-07 18:00:00";
			finishDate = format.parse(finish).getTime();
			String pauseTime = "2012-10-07 13:00:00";
			Long pauseDate = format.parse(pauseTime).getTime();
			String resumeTime = "2012-10-07 13:30:00";
			Long resumeDate = format.parse(resumeTime).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(2,3,1,'调整top3新闻','调整top3新闻的图片,排版,位置等',5," + date + ",6," + resumeDate + "," + pauseDate + "," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-08 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(2,3,1,'调整功能按钮','调整功能按钮的图片,排版,位置等',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-07 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(3,3,2,'实现新闻分类','实现新闻的国内,国际,同城等分类',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-08 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			pauseTime = "2012-10-08 13:00:00";
			pauseDate = format.parse(pauseTime).getTime();
			resumeTime = "2012-10-08 13:30:00";
			resumeDate = format.parse(resumeTime).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(3,3,2,'调整新闻封面图片','调整事件封面图片的大小,比例等',5," + date + ",6," + resumeDate + "," + pauseDate + "," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-07 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(4,3,3,'实现修改字体','实现修改信息正文的字体大小',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-08 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(4,3,3,'实现关于功能','实现关于功能,修改关于功能BUG',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-07 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-07 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(5,3,4,'实现删除新闻功能','删除新闻,修改事件索引文件,删除数据库,删除文件',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
			time = "2012-10-08 10:00:00";
			date = format.parse(time).getTime();
			finish = "2012-10-08 18:00:00";
			finishDate = format.parse(finish).getTime();
			ps = conn.prepareStatement("insert into xtask_tasks(aid,pid,fromTid,tname,tdesc,status,createTime,forecast,resumeTime,pauseTime,completeTime,theActual) " +
					"values(5,3,4,'实现删除事件功能','删除数据库,删除文件',5," + date + ",6,null,null," + finishDate + ",6)");
			ps.execute();
			
//			conn.commit();
			
			//添加问题表数据
			time = "2012-10-08 18:05:00";
			date = format.parse(time).getTime();
			ps = conn.prepareStatement("insert into xtask_question(tid,content,createtime) " +
					"values(1,'这个任务太简单了吧，不给力啊'," + date + ")");
			ps.execute();
			
			conn.commit();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} catch (ParseException e) {
			e.printStackTrace();
		} finally{
			try {
				ps.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
